<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page session="false" %>
<%@ page import="javax.servlet.http.HttpSession" %>
<%@ page import="javax.servlet.http.Cookie" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>注销 - 网吧管理系统</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <header class="lyear-layout-header">
            <nav class="navbar navbar-default">
                <div class="topbar">
                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title">注销</span>
                    </div>
                </div>
            </nav>
        </header>

        <main class="lyear-layout-content">
            <div class="container-fluid">
                <h2>注销中...</h2>
                <p>正在注销您的账户，请稍等...</p>

                <%
                    // 获取当前会话对象
                    HttpSession session = request.getSession(false);
                    if (session != null) {
                        session.invalidate();  // 使会话无效，注销当前用户
                    }

                    // 清除之前存储在浏览器中的登录相关Cookie
                    Cookie[] cookies = request.getCookies();
                    if (cookies != null) {
                        for (Cookie cookie : cookies) {
                            if ("username".equals(cookie.getName()) || "password".equals(cookie.getName())) {
                                cookie.setMaxAge(0); // 设置Cookie过期
                                cookie.setPath("/");  // 设置Cookie路径
                                response.addCookie(cookie);  // 添加到响应中
                            }
                        }
                    }

                    // 重定向到登录页面
                    response.sendRedirect("login.jsp");
                %>
            </div>
        </main>
    </div>
</div>

<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/scripts.min.js"></script>
</body>
</html>
